﻿using Dapper;
using System.Collections.Generic;
using System.Data.SqlClient;
using yunbo.Model.SM;

namespace yunbo.Repositorys.SMRepositorys
{
    public class WMS_LLCKXXRepository
    {
        public string data = "Data Source=121.37.93.71;Initial Catalog=FanXingMES;User ID=sa;Password=geili@2025;";

        public int AddllckXX(TJWMS_LLCKXX wMS_LLCKXX)
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                
                string sql = $@"INSERT INTO [dbo].[wms_llckxx](wl_code, llckxx_wlmc, llckxx_wlfl, llckxx_ggxh, llckxx_wldw, llck_code, llckxx_code, llckxx_ckck, llckxx_cksl)
                                values('{wMS_LLCKXX.wl_code}','{wMS_LLCKXX.llckxx_wlmc}','{wMS_LLCKXX.llckxx_wlfl}','{wMS_LLCKXX.llckxx_ggxh}','{wMS_LLCKXX.llckxx_wldw}','{wMS_LLCKXX.llck_code}','{wMS_LLCKXX.llckxx_code}','{wMS_LLCKXX.llckxx_ckck}','{wMS_LLCKXX.llckxx_cksl}')";
                int ll = connection.Execute(sql);
                return ll;
            }
        }
        public List<WMS_LLCKXX> GetWMS_LLCKXXes(string code)
        {
            using (SqlConnection connection = new SqlConnection(data))
            {
                string sql = $@" select ckxx.[wl_code],ckxx.[llckxx_wlmc],ckxx.[llckxx_cksl],llck.[llck_zt],fl.dictionary_name,wl.[wl_dw],ck.ck_name,dw.dw_name,ckxx.llck_code,ck.ck_code
                                 from [dbo].[wms_llckxx] ckxx
                                 LEFT JOIN
	                                [dbo].[bd_wl] AS wl
	                                ON ckxx.wl_code=wl.wl_code
	                                LEFT JOIN 
	                                [dbo].[dictionary] AS fl
	                                ON fl.dictionary_id=wl.wl_fl
	                                LEFT JOIN 
	                                [dbo].[bd_dw] AS dw
	                                ON dw.[dw_id]=wl.wl_dw
	                                LEFT JOIN 
	                                [dbo].[wms_llck] AS llck
	                                ON ckxx.[llck_code]=llck.llck_code
		                                LEFT JOIN 
	                                [dbo].[wbd_ck] AS ck
	                                ON ck.[ck_code]=ckxx.[llckxx_ckck]
	                                where ckxx.[llck_code]='{code}'";
                List<WMS_LLCKXX> wMS_LLCKXXes=connection.Query<WMS_LLCKXX>(sql).ToList();
                return wMS_LLCKXXes;
            }
        }
    }
}
